﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FCMS.Attributes;

namespace FCMS.Extensions
{
    public static class EnumExtensions
    {
        public static bool Contains(this Enum parent, Enum ele)
        {
            return ((int)(object)parent | (int)(object)ele) == (int)(object)parent;
        }

        public static string GetAttachBinderData(this Enum data)
        {
            var dataType = data.GetType();
            var fileInfo = dataType.GetField(data.ToString());
            var customAttributes = fileInfo.GetCustomAttributes(typeof(AttachBinderDataAttribute), false);
            var attribute = (AttachBinderDataAttribute)customAttributes.OfType<AttachBinderDataAttribute>().FirstOrDefault();

            return attribute != null ? attribute.Name : data.ToString();
        }
    }
}
